import { createSlice } from "@reduxjs/toolkit";
import { Project } from "types/project";
import { User } from "types/user";
import { RootState } from "store";

interface State {
  modalOpen: boolean;
  projects: Project[];
  user: User | null;
}

const initialState: State = {
  modalOpen: false,
  projects: [],
  user: null,
};

export const projectListSlice = createSlice({
  name: "projectListSlice",
  initialState,
  reducers: {
    // https://immerjs.github.io/immer/
    openModal(state) {
      state.modalOpen = true;
    },
    closeModal(state) {
      state.modalOpen = false;
    },
  },
});

export const projectListActions = projectListSlice.actions;

export const selectProjectModalOpen = (state: RootState) =>
  state.projectList.modalOpen;
